package io.demo2_File流;

import java.io.*;

public class Test {
    public static void main1(String[] args) throws Exception{
        FileInputStream fis=new FileInputStream("d:/1.txt");
        // 每次只读取一个字节，所读取的数据作为返回值返回出来
//        System.out.println((char)fis.read());
//        System.out.println((char)fis.read());
        File f=new File("d:/1.txt");
        ;
        byte[]arr=new byte[(int)f.length()];

        //返回值表示本次一共读取了几个字节
        int len=fis.read(arr);
        System.out.println("读取字节数："+len+",读取内容："+new String(arr,0,len,"gbk"));

    }

    public static void main22(String[] args)throws Exception {
        FileInputStream fis=new FileInputStream("d:/1.txt");
        int data;
        while((data=fis.read())!=-1){
            System.out.print((char)data);
        }
        fis.close();
    }

    public static void main(String[] args)throws Exception {
        FileInputStream fis=new FileInputStream("d:/1.txt");
        int len;
        byte[]arr=new byte[5];
        while((len=fis.read(arr))!=-1){
            System.out.print(new String(arr,0,len,"gbk"));
        }
        fis.close();
    }
}
